//
//  StartSellTimeViewController.m
//  LazyCat
//
//  Created by Abner on 16/5/4.
//  Copyright © 2016年 zhanshu. All rights reserved.
//

#import "StartSellTimeViewController.h"
#import "UUDatePicker.h"

@interface StartSellTimeViewController ()<UUDatePickerDelegate>
{
    NSString *time_start;
    NSString *time_end;
    BOOL scroll_start; //判断是否有滑动
    BOOL scroll_end;
    NSString *dateStr;
}

@property(nonatomic,strong)UIScrollView *scrollView;

@end

@implementation StartSellTimeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    time_start = @"";
    time_end =@"";
    scroll_start = NO;
    scroll_end = NO;
    
    self.view.backgroundColor = BackColor;
    [self initNav:@"开售时间" doBack:YES];
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 63, ScreenWidth, 1)];
    lineView.backgroundColor = [UIColor lightGrayColor];
    lineView.alpha = 0.2;
    [self.navBar addSubview:lineView];
    self.view.backgroundColor = SetColorRGBValue(0xF9F9F9, 1.0);
    
    
    UIScrollView *scr = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64)];
    scr.contentSize = CGSizeMake(ScreenWidth, 477);
    scr.scrollEnabled = NO;
    self.scrollView = scr;
    scr.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.scrollView];
    
    UIButton *OKBt = [UIButton buttonWithType:UIButtonTypeCustom];
    [OKBt setTitle:@"确定" forState:UIControlStateNormal];
    OKBt.frame = CGRectMake(0, ScreenHeight-50, ScreenWidth, 50);
    OKBt.backgroundColor = SetColorRGBValue(0xff6600, 1.0);
    [OKBt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    OKBt.titleLabel.font = FontSet(18);
    [self.view addSubview:OKBt];
    [OKBt addTarget:self action:@selector(OKBtClicked) forControlEvents:UIControlEventTouchUpInside];
    [self creatUI];
}
#pragma mark --- 创建视图
-(void)creatUI
{
    //获取当前时间
    NSDate *nowDate = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
    dateFormatter.dateFormat = @"yyyy-MM-dd";
    NSString *dateString = [dateFormatter stringFromDate:nowDate];
    dateStr = dateString;
    NSLog(@"当前时间---%@",dateStr);
    
    UILabel *startLb = [[UILabel alloc]initWithFrame:CGRectMake(15, 25, ScreenWidth-30, 15)];
    startLb.text = @"开始时间";
    startLb.textColor = SetColorRGBValue(0x717075, 1.0);
    [self.scrollView addSubview:startLb];
    
    UUDatePicker *datePicker_start = [[UUDatePicker alloc]initWithframe:CGRectMake(0, 52.5, ScreenWidth, 166) Delegate:self PickerStyle:UUDateStyle_YearMonthDay];
    datePicker_start.tag = 301;
    [self.scrollView addSubview:datePicker_start];
    
    UILabel *endLb = [[UILabel alloc]initWithFrame:CGRectMake(15, 243.5, ScreenWidth-30, 15)];
    endLb.text = @"结束时间";
    endLb.textColor = SetColorRGBValue(0x717075, 1.0);
    [self.scrollView addSubview:endLb];
    
    UUDatePicker *datePicker_end = [[UUDatePicker alloc]initWithframe:CGRectMake(0, 271, ScreenWidth, 166) Delegate:self PickerStyle:UUDateStyle_YearMonthDay];
    datePicker_end.tag = 302;
    [self.scrollView addSubview:datePicker_end];
    
}

-(void)uuDatePicker:(UUDatePicker *)datePicker year:(NSString *)year month:(NSString *)month day:(NSString *)day hour:(NSString *)hour minute:(NSString *)minute weekDay:(NSString *)weekDay
{
    if (datePicker.tag == 301) {
        time_start = [NSString stringWithFormat:@"%@-%@-%@",year,month,day];
        scroll_start = YES;
    }else if (datePicker.tag == 302){
        time_end = [NSString stringWithFormat:@"%@-%@-%@",year,month,day];
        scroll_end = YES;

    }
    
}
-(void)OKBtClicked
{
   
    if (!scroll_start) {
        time_start = dateStr;
    }
    if (!scroll_end) {
        time_end = dateStr;
    }
  
    if (self.overSelectedDateBlock) {
        self.overSelectedDateBlock(time_start,time_end);
    }
    [self.navigationController popViewControllerAnimated:YES];
    
    
  
    
}
-(void)viewDidDisappear:(BOOL)animated
{
  
    if (![time_start isEqualToString:@""] && ![time_end isEqualToString:@""]) {
        if (self.overSelectedDateBlock) {
            self.overSelectedDateBlock(time_start,time_end);
        }
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
